package AsLayers.Util
{

	public class Geo
	{
		static public var INCHES_PER_UNIT :Object= { 
         'inches': 1.0,
         'ft': 12.0,
         'mi': 63360.0,
         'm': 39.3701,
         'km': 39370.1,
         'dd': 4374754
        }
        INCHES_PER_UNIT["in"]= INCHES_PER_UNIT.inches;
        INCHES_PER_UNIT["degrees"] = INCHES_PER_UNIT.dd;
    
        static public var DOTS_PER_INCH:Number = 72;
        
		static public function normalizeScale  (scale:Number):Number {
             var normScale:Number = (scale > 1.0) ? (1.0 / scale) 
                                  : scale;
             return normScale;
        }
        
		static public function getResolutionFromScale(scale:Number, units:String):Number {
          if (units == null) {
             units = "degrees";
          }
          var normScale:Number = normalizeScale(scale);
          var resolution :Number= 1 / (normScale * INCHES_PER_UNIT[units]
                                    * DOTS_PER_INCH);
         return resolution;
       }
       
       static public function getScaleFromResolution  (resolution:Number, units:String):Number {
         if (units == null) {
          units = "degrees";
         }
         var scale:Number = resolution * INCHES_PER_UNIT[units] *
                    DOTS_PER_INCH;
         return scale;
       }
	}
}